File & Image Upload Widget
(With Integrated Cloud Storage)
100% Serverless File Upload Widget
Powered by Upload.io
DMCA Compliant โข GDPR Compliant โข 99.9% Uptime SLA
Supports: Rate Limiting, Volume Limiting, File Size & Type Limiting, JWT Auth, and more...
Installation
Install via NPM:
npm install uploader
Or via YARN:
yarn add uploader
Or via a <script>
tag:
<script src="https://js.upload.io/uploader/v2"></script>
Usage
Initialize
Initialize once at the start of your application:
const { Uploader } = require("uploader");
const uploader = Uploader({
apiKey: "free"
});
uploader.open({ multi: true }).then(files => {
if (files.length === 0) {
console.log('No files selected.')
} else {
console.log('Files uploaded:');
console.log(files.map(f => f.fileUrl));
}
}).catch(err => {
console.error(err);
});
Get the Result
.open()
returns Promise<Array<UploaderResult>>
:
{
fileUrl: "https://upcdn.io/FW25...",
filePath: "/uploads/example.jpg",
editedFile: undefined,
originalFile: {
fileUrl: "https://upcdn.io/FW25...",
filePath: "/uploads/example.jpg",
accountId: "FW251aX",
originalFileName: "example.jpg",
file: { ... },
size: 12345,
lastModified: 1663410542397,
mime: "image/jpeg",
metadata: {
...
},
tags: [
"tag1",
"tag2",
...
]
}
}
๐ More Examples
Creating an Image Uploader โ Try on CodePen:
Uploader contains a built-in image cropper:
The cropper appears by default, but can be disabled with crop: false
(see examples below):
uploader
.open({
multi: false,
mimeTypes: ["image/jpeg", "image/png", "image/webp"],
editor: {
images: {
crop: true,
cropShape: "circ",
cropRatio: 1 / 1
}
}
})
.then(files => alert(JSON.stringify(files)));
Creating a "Single File" Upload Button โ Try on CodePen:
uploader.open().then(files => alert(JSON.stringify(files)));
Creating a "Multi File" Upload Button โ Try on CodePen:
uploader.open({ multi: true }).then(files => alert(JSON.stringify(files)));
You can use Uploader as a dropzone โ rather than a modal โ by specifying layout: "inline"
and a container:
uploader.open({
multi: true,
layout: "inline",
container: "#example_div_id",
onUpdate: (files) => console.log(files)
})
Note:
- You must set
position: relative
, width
and height
on the container div
. - The
Finish
button is hidden by default in this mode (override with "showFinishButton": true
).
โ๏ธ Configuration
All configuration is optional.
uploader
.open({
container: "body",
layout: "modal",
locale: myCustomLocale,
maxFileCount: 5,
maxFileSizeBytes: 1024 ** 2,
mimeTypes: ["image/jpeg"],
multi: false,
onUpdate: files => {},
showFinishButton: true,
showRemoveButton: true,
styles: {
colors: {
primary: "#377dff",
active: "#528fff"
},
fontSizes: {
base: 16
}
},
path: {
fileName: "Example.jpg",
folderPath: "/uploads"
},
metadata: {
hello: "world"
},
tags: ["profile_picture"],
editor: {
images: {
crop: true,
cropRatio: 4 / 3,
cropShape: "rect"
}
},
})
.then(files => alert(files))
๐ณ๏ธ Localization
Default is EN_US:
const myCustomLocale = {
"error!": "Error!",
"done": "Done",
"addAnotherFile": "Add another file...",
"addAnotherImage": "Add another image...",
"cancel": "cancel",
"cancelled!": "cancelled",
"continue": "Continue",
"crop": "Crop",
"finish": "Finished",
"finishIcon": true,
"image": "Image",
"maxFilesReached": "Maximum number of files:",
"maxImagesReached": "Maximum number of images:",
"maxSize": "File size limit:",
"next": "Next",
"of": "of",
"orDragDropFile": "...or drag and drop a file.",
"orDragDropFiles": "...or drag and drop files.",
"orDragDropImage": "...or drag and drop an image.",
"orDragDropImages": "...or drag and drop images.",
"pleaseWait": "Please wait...",
"removed!": "removed",
"remove": "remove",
"skip": "Skip",
"unsupportedFileType": "File type not supported.",
"uploadFile": "Upload a File",
"uploadFiles": "Upload Files",
"uploadImage": "Upload an Image",
"uploadImages": "Upload Images"
}
Where are my files stored?
Uploader uses Upload.io as a file storage & file hosting backend.
Upload.io benefits developers with:
- Zero Setup (Start uploading in the next few minutes!)
- Pre-Integrated Storage (All you need is an Upload API key)
- Fast File Hosting (Worldwide CDN, 300 Nodes)
- Powerful Rules Engine (Rate Limiting, Traffic Limiting, IP Blacklisting, Expiring Links, etc)
- File Transformations (Image Resizing, Cropping, Optimization, etc)
๐ง Can I bring my own file storage?
Yes! Upload.io supports custom S3 buckets.
You still need an Upload.io account to use the widget.
๐ API Support
You can use Upload.io's File Upload API directly to achieve:
- File uploading.
- File listing.
- File deleting.
- And more...
Uploading a "Hello World"
text file is as simple as:
curl --data "Hello World" \
-u apikey:free \
-X POST "https://api.upload.io/v1/files/basic"
Note: Remember to set -H "Content-Type: mime/type"
when uploading other file types!
Read the File Upload API docs ยป
Building From Source
Please read: BUILD.md
Contribute
If you would like to contribute to Uploader:
- Add a GitHub Star to the project (if you're feeling generous!).
- Determine whether you're raising a bug, feature request or question.
- Raise your issue or PR.
For more examples, see CodePen and CodeSandbox.
License
MIT